package com.sanqi.work.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sanqi.common.annotation.Log;
import com.sanqi.common.core.controller.BaseController;
import com.sanqi.common.core.domain.AjaxResult;
import com.sanqi.common.enums.BusinessType;
import com.sanqi.work.domain.WorkUserAccount;
import com.sanqi.work.service.IWorkUserAccountService;
import com.sanqi.common.utils.poi.ExcelUtil;
import com.sanqi.common.core.page.TableDataInfo;

/**
 * 用户账号Controller
 * 
 * @author duany
 * @date 2025-10-09
 */
@RestController
@RequestMapping("/work/account")
@Api(tags="用户账号")
public class WorkUserAccountController extends BaseController
{
    @Autowired
    private IWorkUserAccountService workUserAccountService;

    /**
     * 查询用户账号列表
     */
    @PreAuthorize("@ss.hasPermi('work:account:list')")
    @GetMapping("/list")
    @ApiOperation(value="用户账号-查询用户账号列表", notes="用户账号-查询用户账号列表")
    public TableDataInfo list(WorkUserAccount workUserAccount)
    {
        startPage();
        List<WorkUserAccount> list = workUserAccountService.selectWorkUserAccountList(workUserAccount);
        return getDataTable(list);
    }

    /**
     * 导出用户账号列表
     */
    @PreAuthorize("@ss.hasPermi('work:account:export')")
    @Log(title = "用户账号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value="用户账号-导出用户账号列表", notes="用户账号-导出用户账号列表")
    public void export(HttpServletResponse response, WorkUserAccount workUserAccount)
    {
        List<WorkUserAccount> list = workUserAccountService.selectWorkUserAccountList(workUserAccount);
        ExcelUtil<WorkUserAccount> util = new ExcelUtil<WorkUserAccount>(WorkUserAccount.class);
        util.exportExcel(response, list, "用户账号数据");
    }

    /**
     * 获取用户账号详细信息
     */
    @PreAuthorize("@ss.hasPermi('work:account:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value="用户账号-获取用户账号详细信息", notes="用户账号-获取用户账号详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(workUserAccountService.selectWorkUserAccountById(id));
    }

    /**
     * 新增用户账号
     */
    @PreAuthorize("@ss.hasPermi('work:account:add')")
    @Log(title = "用户账号", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value="用户账号-新增用户账号", notes="用户账号-新增用户账号")
    public AjaxResult add(@RequestBody WorkUserAccount workUserAccount)
    {
        return toAjax(workUserAccountService.insertWorkUserAccount(workUserAccount));
    }

    /**
     * 修改用户账号
     */
    @PreAuthorize("@ss.hasPermi('work:account:edit')")
    @Log(title = "用户账号", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value="用户账号-修改用户账号", notes="用户账号-修改用户账号")
    public AjaxResult edit(@RequestBody WorkUserAccount workUserAccount)
    {
        return toAjax(workUserAccountService.updateWorkUserAccount(workUserAccount));
    }

    /**
     * 删除用户账号
     */
    @PreAuthorize("@ss.hasPermi('work:account:remove')")
    @Log(title = "用户账号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	@ApiOperation(value="用户账号-删除用户账号", notes="用户账号-删除用户账号")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(workUserAccountService.deleteWorkUserAccountByIds(ids));
    }
}
